/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.tests;

import static org.junit.Assert.assertEquals;
import ac.jp.u_tokyo.SyncLib.Mod;
import ac.jp.u_tokyo.SyncLib.Sync;
import ac.jp.u_tokyo.SyncLib.SynchronizationFailedException;

public class SyncTestBase
{
	protected void assertPreservation(Mod[] output, Mod[] input) {
		for (int i = 0; i < input.length; i++)
			assertEquals("index: " + i, output[i], output[i].merge(input[i]));

	}
	
	protected Mod[] checkedSynchronize(Sync sync, Mod[] mods) throws SynchronizationFailedException {
		Mod[] result = sync.synchronize(mods);
		assertPreservation(result, mods);
		return result;
	}

	protected Mod[] checkedResynchronize(Sync sync, Object[] values, Mod[] mods) throws SynchronizationFailedException {
		Mod[] result = sync.resynchronize(values, mods);
		assertPreservation(result, mods);
		return result;
	}
}
